document.domain = 'iefgames.com';		//重要

var Iefgames_CS;
(function() {
	if ($defined(Iefgames_CS)) {
		return ;
	}
	
	Iefgames_CS = {
		Core: {
			baseUri : 'http://cs.iefgames.com:8080'
		},
		
		Cookie: {
			Options: {},
			usUuidCookieName: 'usUuid',
			csUuidCookieName: 'csUuid'
		},
		
		Ajax: function() {
			var xmlHttp = null;
			try {
				if (!!ActiveXObject) {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
			} catch (e) {
				try {
					xmlHttp = new XMLHttpRequest();
				} catch (e) {
				}
			}
			
			return xmlHttp;
		},
		
		Debugger: function() {
			var isDebug = true;
			if (window.location.host.indexOf('debug') != 0) {
				return {
					isDebug: isDebug,
					add: function() {}
				}
			}
			
			var str = '';
			(function() {
				$(document.body).grab(new Element('div', {
					'id': 'debuggerPanel',
					'html': 'debugger me',
					'events': {
						'click': function() {
							alert(str);
						}
					}
				}));
			}).delay(500, this)
			
			//shoutName, params, function, 
			var add = function() {
				if (!isDebug) {
					return;
				}
				
				for (var i=1; i<=arguments.length; ++i) {
					switch (i%3) {
						case 1: str += 'name:' + arguments[i-1]; break;
						case 2: str += 'prars:' + arguments[i-1]; break;
						case 3: str += 'fn:' + arguments[i-1]; break;
						default:
					}
					
					str += '\n';
				}
			}
			
			return {
				isDebug: isDebug,
				add: add
			}
		}(),
		
		generateUuid: function() {
			return hex_md5((function() {
				var i = 0;
				var tmp = '';
				while ((i++) != 60) {
					tmp += $random(0, 9);
				}
				
				return tmp;
			})() + new Date().getTime());
		},
		
		isCs: function() {
			if (!(window.location.href.replace('http://' + window.location.host + '/', ''))
					|| !(window.location.href.replace('http://' + window.location.host + '/index.html', ''))) {
				return true;
			} else {
				return false;
			}
		}()
	}
	
	Iefgames_CS._d = Iefgames_CS.Debugger.add
	
	Iefgames_CS.Shout = function() {
		var ShoutHash = new Hash();
		var reg = function() {
			if (!arguments[0]
					|| $type(arguments[0]) != 'string'
					|| $type(arguments[1]) != 'function') {
				return;
			}
			
			if (ShoutHash.getKeys().contains(arguments[0])) {
				return;
			}
			
			ShoutHash.set(arguments[0], arguments[1]);
			
			Iefgames_CS._d(arguments[0], null, arguments[1]);
		}
		
		var callback = function(sName, sPara) {
			if ($type(sName) != 'string'
					|| $type(ShoutHash.get(sName)) != 'function') {
				return;
			}
			
//			console.log("call shout. shout name is " + sName);
			$chk(sPara) ? ShoutHash.get(sName)(sPara) : ShoutHash.get(sName)();
			
//			if (!arguments[0]
//					|| $type(arguments[0]) != 'string') {
//				return;
//			}
//			
//			if ($type(ShoutHash.get(arguments[0])) != 'function') {
//				return;
//			}
//			
//			var fn = ShoutHash.get(arguments[0]);
//			for (var i=1; i<=arguments.length; ++i) {
//				!arguments[i] ? fn() : fn(arguments[i]);
//			}
//			//TODO: this is bug.
//			ShoutHash.get(arguments[0]).apply(this, arguments.erase(arguments[0]));
		}
	
		Iefgames_CS._$ = reg;
		Iefgames_CS._ = callback;
		return {}
	}();
	
})()
